<template>
  <view>
    <view v-for="(item, index) in activeList" :key="item.id">

      <view class="news_box" v-if="index % 2 === 0" @click="goVaPreview(item)">
        <view class="news_content content_left">
          <view class="news_name">{{ item.title }}</view>
          <view class="news_date">{{ item.activity_time | dateMimute }}</view>
          <view class="bottom_box">
            <view class="img_box">
              <image class="img" :lazy-load="true" mode="aspectFit" :src="logoUlr(item.company_name)"></image>
            </view>
            <view class="news_cneter" v-if="item.brand_id == 1">锦龙汽车集团</view>
            <view class="news_cneter" v-else>{{ item.company_name ? item.company_name : '奥迪体验中心' }}</view>
          </view>
        </view>
        <view class="news_img">
          <image class="img" :lazy-load="true" mode="aspectFill" :src="`${baseUrl}/images/news/${item.cover_img}`">
          </image>
        </view>
      </view>

      <view class="news_box" v-else @click="goVaPreview(item)">
        <view class="news_img">
          <image class="img" :lazy-load="true" mode="aspectFill" :src="`${baseUrl}/images/news/${item.cover_img}`">
          </image>
        </view>
        <view class="news_content content_right">
          <view class="news_name">{{ item.title }}</view>
          <view class="news_date">{{ item.activity_time | dateMimute }}</view>
          <view class="bottom_box">
            <view class="img_box">
              <image class="img" :lazy-load="true" mode="aspectFit" :src="logoUlr(item.company_name)"></image>
            </view>
            <view class="news_cneter" v-if="item.brand_id == 1">锦龙汽车集团</view>
            <view class="news_cneter" v-else>{{ item.company_name ? item.company_name : '奥迪体验中心' }}</view>
          </view>
        </view>
      </view>

    </view>
  </view>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'NewsItem',
  props: {
    activeList: {
      type: Array,
      default: function () {
        return []
      }
    }
  },
  data() {
    return {
      // 基础路径
      baseUrl: this.$baseUrl
    }
  },
  methods: {
    // 跳转外链
    goVaPreview(e) {
      if (e.wx_link === '') {
        uni.navigateTo({
          url: `/News/NewsDetails?item=${e.id}`
        })
      } else {
        // 外链
        // let info = { src: e.wx_link, title: '新闻详情' }
        // wx.navigateTo({
        //   url: `/pages/goVaPage?info=${encodeURIComponent(
        //     JSON.stringify(info)
        //   )}`,
        // })
        wx.navigateTo({
          url: `/pages/goVaPage?info=${e.wx_link}`
        })
      }
    },
    logoUlr(has) {
      let base = `${this.baseUrl}/images/brand/`
      if (has) {
        return `${base}${this.groupInfo[1]?.logoUlr}`
      } else {
        return `${base}${this.groupInfo[0]?.logoUlr}`
      }
    }
  },
  computed: {
    ...mapState(['groupInfo'])
  }
}
</script>
<style scoped lang="scss">
.news_box {
  display: flex;
  align-items: center;
  margin: 20rpx 30rpx 30rpx 30rpx;
  background-color: #fafafa;
  // box-shadow: $theme-shadow;
  // box-shadow: 0px 0px 18px 9px rgba(5, 5, 5, 0.03);
  padding: 30rpx 20rpx;
  justify-content: space-between;
  border-radius: 12rpx;
  border: 3rpx solid rgba(0, 0, 0, 0.05);

  .news_content {
    height: 180rpx;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    // flex: 1;
    width: 430rpx;
    // height: 190rpx;
    box-sizing: border-box;

    .news_date {
      font-size: 22rpx;
    }

    .news_name {
      font-size: 26rpx;
      color: #222222;
      font-weight: 600;
      overflow: hidden;
      display: -webkit-box;
      text-overflow: ellipsis;
      text-overflow: -o-ellipsis-lastline;
      line-clamp: 2;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }

    .bottom_box {
      display: flex;
      justify-content: flex-start;
      // align-content: center;
      align-items: center;

      .img_box {
        width: 50rpx;
        height: 50rpx;

        .img {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }

      .news_cneter {
        font-size: 24rpx;
        margin-left: 10rpx;
      }
    }
  }

  .content_left {
    padding-right: 30rpx;
  }

  .content_right {
    padding-left: 30rpx;
  }

  .news_img {
    width: 300rpx;
    height: 180rpx;
    border-radius: 20rpx;
    overflow: hidden;

    .img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
